﻿HmJS.$Import('core.core');

/*
---
name: String.Hex
version: 0.3-1
description: String Hex encode/decode.
license: MIT-style
download: http://mootools.net/forge/p/string_cryptography
source: http://github.com/sixtyseconds/mootools-string-cryptography
authors: [Christopher Pitt, Enrique Erne]
requires: 
- Core/String
provides: [String.toHex, String.fromHex]
...
*/

HmJS.register('crypt.string.cryptographyhex', function ($ns) {

	String.implement({

		'toHex': function () {
			var r = '', i = 0,
					limit = this.length;

			while (i < limit) {
				r += this.charCodeAt(i++).toString(16);
			}

			return r;
		},

		'fromHex': function () {
			var r = s = '',
					e = this.length;

			while (e > 0) {
				s = e - 2;
				r = String.fromCharCode('0x' + this.substring(s, e)) + r;
				e = s;
			}

			return r;
		}

	});

});
